import java.security.Key;
import java.util.*;

/**
 * 面试题，有序列表，如何获取id
 */
public class JavaDemo2 {

    static final LinkedHashMap<Integer, User> map = new LinkedHashMap<>();
    static final List<Integer> ids = new ArrayList<>();


    public static void put(User v) {
        if (map.containsKey(v.id)) {
            // 移除 之前的逻辑
            ids.remove(ids.remove(v.id));
            map.remove(v.id);
        }
        map.put(v.id, v);
        ids.add(v.id);
    }

    public static User get(Integer key) {
        return map.get(key);
    }

    public static List<Integer> getKeyList() {
        return ids;
    }



    public static void main(String[] args) {
        LinkedList<String> stringLinkedList=new LinkedList<>();
        stringLinkedList.add(0,"A");
        stringLinkedList.add(1,"A");
        stringLinkedList.add(3,"A");
        stringLinkedList.add(4,"A");
        stringLinkedList.add(2,"A");
        stringLinkedList.get(1);
    }
    public static class User {
        Integer id;
        Integer age = 0;
        String name;
    }

}
